/*
 * @Author: 用户信息
 * @Date: 2021-03-26 09:20:25
 * @LastEditTime: 2021-04-28 17:46:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \testc:\Users\JOJO\Desktop\vue-demo\my-app\src\api\user.js
 */
// import axios from "axios";
import axios from "../axios/index";
export default {
  /**
   * code 账号 password 密码
   * type用于判断是学生还是老师,默认学生
   */
  //老师/学生登录
  login: ({ code, password, type = false } = {}) =>
    // axios
    //   .post(`/api/user/${type ? "admin/login" : "login"}`, { code, password })
    //   .then(function(response) {
    //     return response.data;
    //   }),
    axios
      .post(`user/${type ? "admin/login" : "login"}`, { code, password })
      .then(function(response) {
        return response.data;
      }),
  //注册
  reg: (data = {}) =>
    axios.post(`user/register`, data).then(function(response) {
      return response.data;
    }),
  //验证学号
  getValidate: code =>
    axios.get(`user/reg/validateCode/` + code).then(function(response) {
      console.log(response.data);
      return response.data;
    }),
  //获取学院
  getColleges: () =>
    axios.get(`info/colleges`).then(function(response) {
      return response.data.data;
    }),
  //验证邮箱
  getEmail: email =>
    axios.get(`user/reg/validateMail/` + email).then(function(res) {
      console.log("验证邮箱", res);
      return res.data;
    }),
  // 个人信息页面
  userinfo: () =>
    axios
      .get("user/userinfo")
      .then(function(response) {
        return response.data;
      })
      .catch(function(err) {
        console.log("直接炸裂" + err);
      }),
  // 修改个人信息
  updateUserInfo: (data = {}) =>
    axios
      .post(`user/updateUserInfo`, data)
      .then(function(response) {
        console.log(response);
        return response.data;
      })
      .catch(function(err) {
        console.log(err);
      }),
  uploadIcon: formData =>
    axios
      .post("file/uploadIcon", formData, {
        headers: { "Content-Type": "multipart/form-data" }
      })
      .then(function(response) {
        console.log(response);
        return response.data;
      })
      .catch(function(err) {
        console.log(err);
      }),
  // 退出方法
  userlogout: () =>
    axios.get(`user/logout/`).then(function(response) {
      console.log(response.data);
      return response.data;
    }),
  setToken: token => (localStorage["_t"] = token),
  getToken: () => localStorage["_t"]
};
